<?php

function html_element($type, $txt, $attr = null, $opt = [])
{
    $pro = '';

    if (isset($opt['class']))
        $pro .= ' class="'.$opt['class'].'"';
    else if ($type == 'button')
        $pro .= ' class="btn btn-default btn-primary"';

    if (isset($opt['id']))
        $pro .= ' id="'.$opt['id'].'"';

    if ($attr !== null)
        $pro .= ' '.$attr;

    if ($type == 'a') {
        $e = '<a href="javascript:void(0)"';
        $e .= $pro;
        $e .= '>'.$txt.'</a>';

    } else if ($type == 'button') {
        $e = '<button type="button"';
        $e .= $pro;
        $e .= '>'.$txt.'</button>';
    }

    return $e;
}

function html_link($url, $tag = '#datalist', $element = null, $txt = '链接', $confirm = null, $ajax = "true", $opt = [])
{
    $attr = ' kyo-link=\'';
    $attr .= '"url": "'.$url.'",';
    $attr .= '"ajax": '.$ajax;
    $attr .= ',"tag": "'.$tag.'"';
    if ($confirm !== null)
        $attr .= ',"confirm": "'.$confirm.'"';
    $attr .= '\'';

    if ($element !== null) {
        return html_element($element, $txt, $attr, $opt);
    }

    return $attr;
}

function html_pop($url, $w = null, $h = null, $title = null, $element = null, $txt = '弹出框', $opt = [])
{

    $attr = ' kyo-pop=\'';
    $attr .= '"url": "'.$url.'",';
    if ($w !== null)
        $attr .= '"w": '.$w;
    if ($h !== null)
        $attr .= ',"h": '.$h;
    if ($title !== null)
        $attr .= ',"title": "'.$title.'"';
    if (isset($opt['cover']))
        $attr .= ',"cover": "'.$opt['cover'].'"';
    if (isset($opt['bc']))
        $attr .= ',"bc": "'.$opt['bc'].'"';
    $attr .= '\'';

    if ($element !== null) {
        return html_element($element, $txt, $attr, $opt);
    }

    return $attr;
}

